<?php include 'inc/top.php';?>
<?php include 'inc/menu_top.php';?>
<?php include 'inc/boxtop.php';?>
<div id="home">
<h2>Giỏ hàng của bạn</h2>
<?php if (isset($_SESSION["cart"]) && !empty($_SESSION["cart"])):?>
<form name="frCart"  id="frCart" method = "post" action="act/updateCart.php">
	<table width="100%" border="1px" align="center">
	<thead>
	<tr>
		<th>Mã sản phẩm</th><th>Tên sản phẩm</th><th>Số lượng</th><th>Đơn giá</th><th>Thành tiền</th>
	</tr>
	</thead>
	<tbody>
	<style>
	.cell_style {text-align : center}
	</style>
	<?php 
	$array_main_cart = array();
	foreach ($_SESSION["cart"] as $p_id => $p_num){
		$array_cart = array();
		$array_cart["p_id"]  = $p_id;
		$sql = "SELECT product_name as p_name ,product_price as p_price FROM tb_product WHERE product_id = ".$p_id;
		$query = mysql_query($sql);
		while ($data = mysql_fetch_array($query)) {
			$array_cart["p_name"] = $data["p_name"];
			$array_cart["p_num"]= $p_num;
			$array_cart["p_price"] = $data["p_price"];
			$array_cart["p_total"] = $p_num*$data["p_price"];
		}
		$array_main_cart[] = $array_cart;
		unset($array_cart);
	}
	foreach ($array_main_cart as $product_info):
	?>
		<tr>
			<td class='cell_style'><input size ='2' type='hidden' id='p_id' name='p_id[]' value='<?php echo $product_info['p_id']; ?>' /><?php echo $product_info['p_id']; ?></td>
			<td class='cell_style'><input size ='2' type='hidden' id='p_name' name='p_name[]' value='<?php echo $product_info['p_name']; ?>' /><?php echo $product_info['p_name']; ?></td>
			<td class='cell_style'><input size ='2' type='text' id='p_num_text' name='p_num_text[]' value='<?php echo $product_info['p_num']; ?>' /></td>
			<td class='cell_style'><input size ='2' type='hidden' id='p_price' name='p_price[]' value='<?php echo $product_info['p_price']; ?>' /><?php echo $product_info['p_price']; ?></td>
			<td class='cell_style'><input size ='2' type='hidden' id='p_total' name='p_total[]' value='<?php echo $product_info['p_total']; ?>' /><?php echo $product_info['p_total'];?></td>
		</tr>
	<?php endforeach;
	?>
	
	</tbody>
	</table>
	<img id="loader_image" src="style/images/gif/loading_black.gif"  alt="loading...">

<div class = "group_button_cart" >
	<input class="btn_cart btn_cart_first"  type="button" id="bt_continue_cart" name="bt_continue_cart" value="Tiếp tục mua hàng" onclick="goToPage();" > 
	<input class="btn_cart"  type="submit" id="bt_update_cart"   name="bt_update_cart"value="Cập nhật giỏ hàng" > 
	<input class="btn_cart"  type="button" id="bt_finish_cart"  name ="bt_finish_cart" value="Kêt thúc đặt hàng" onclick="saveCart();" > 
</div>
</form>
<?php else : echo "Không có sản phẩm nào cả !";
		endif;
?>

<style>
	.btn_cart { margin: 5px 0px 2px 5px; float:right}
	.btn_cart_first {}
</style>
</div>
<?php include 'inc/sidebar_right.php';?>
<?php include 'inc/bottom.php';?>